package com.zretc.recommend.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zretc.api.pojo.recommendModule.Applications;
import com.zretc.api.pojo.recommendModule.Recommend;
import com.zretc.api.pojo.recommendModule.applicationDTO;
import com.zretc.common.entity.R;
import com.zretc.common.entity.RespResult;
import com.zretc.recommend.service.FileServiceClient;
import com.zretc.recommend.service.recommendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/recommend")
public class RecommendController {
    @Autowired
    private recommendService recommendService;
//内推列表
    @GetMapping("/recommendList")
    public RespResult recommendList(Integer pageNum, Integer pageSize,String cityname,String keywords){
        return R.success(recommendService.getRecommendById(pageNum,pageSize,cityname,keywords));

    }
//内推详情
    @GetMapping("/recommendMsg/{id}")
    public RespResult recommendMsg(@PathVariable Integer id){
        return R.success(recommendService.getMsgById(id));
    }
//发布内推
    @GetMapping("/publish")
    public RespResult publish(@RequestBody Recommend recommend){
        return R.success(recommendService.addRecommend(recommend));
    }
//申请内推
    @PostMapping("/applicate/{id}")
    public RespResult applicate(@PathVariable Integer id,
                                @RequestParam("dto") String applicationDTOStr,
                                @RequestParam("file") MultipartFile file) throws JsonProcessingException {
        //System.out.println(applicationDTOStr);
        Applications application = new ObjectMapper().readValue(applicationDTOStr, Applications.class);
        return R.success(recommendService.applicate(id,application,file));
    }
    @PostMapping("/a")
    public RespResult applicate(
                                @RequestParam("file") MultipartFile[] file) throws JsonProcessingException {
        //System.out.println(applicationDTOStr);

        return R.success(recommendService.aaa(file));
    }
    @PostMapping("/bbb")
    public RespResult test(){
        return recommendService.test();
    }







}
